package io.github.kimmking.gateway.router;

import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;

/**
 * @ClassName LoadBalanceH
 * @Description
 * @Author Jingxiao.Ye
 * @Date 2021/11/21 下午11:39
 * @Version V1.0
 * @Since JDK 11
 */
public class RoundRibbonHttpEndpointRouter implements HttpEndpointRouter {

    private final static AtomicLong cnt = new AtomicLong();

    @Override
    public String route(List<String> endpoints) {
        //轮训
        //2.存储上一个轮训的值,如果节点变化->重新计数，
        long v = cnt.getAndIncrement();
        return endpoints.get((int) (v%endpoints.size()));
    }
}
